﻿using d1Common.Interface;
using d1Project.Tools;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace d1Project.Modules.Common.doConfig.Services
{
    public class doConfigServiceLocal : doConfigServiceBase, IDoConfig
    {
        public override string readConfigFile(string _module, string _path)
        {
            string _dataFileRootPath = this.readLocalConfig("ConfigFileRootPath", null);
            if (_dataFileRootPath == null) return null;
            string _rootPath = DoEnvironment.GetExecutePath();
            if (!_rootPath.EndsWith("/")) _rootPath = _rootPath + "/";
            _dataFileRootPath = _dataFileRootPath.Replace("$", _rootPath);

            _dataFileRootPath = _dataFileRootPath.Replace("\\", "/");
            if (!_dataFileRootPath.EndsWith("/")) _dataFileRootPath = _dataFileRootPath + "/";
            if (!_path.StartsWith("/")) _path = "/" + _path;
            string _fileFullPath = _dataFileRootPath + _module + _path;
            if (!File.Exists(_fileFullPath)) return null;
            return File.ReadAllText(_fileFullPath, Encoding.UTF8);
        }

    }
}